package Day2025_04_12;

import java.util.Arrays;
import java.util.Scanner;

public class Demo08 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), k = in.nextInt();
        int[] arr = new int[n];
        int ret = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            ret += numTwo(arr[i]);
        }
        if (ret >= k) System.out.println(0);
        else {
            Arrays.sort(arr);
            long sum = 0;
            for (int i = 0; i < n; i++) {
                if (arr[i] % 2 != 0) {
                    arr[i] += 1;
                    sum += 1;
                    ret += numTwo(arr[i]);
                    if (ret >= k) break;
                }
            }
            if (ret >= k) System.out.println(ret);
            else {
                while (ret < k) {
                    int min = 0x3f3f3f3f;
                    int x = 0;
                    for (int i = 0; i < n; i++) {
                        if (!isTwo(arr[i])) {
                            int xx = distanceTo(arr[i]);
                            if (xx < min) {
                                x = i;
                                min = xx;
                            }
                        }
                    }
                    sum += min;
                    ret -= numTwo(arr[x]);
                    arr[x] += min;
                    ret += arr[x];
                }
                System.out.println(ret);
            }
        }
    }
    private static int numTwo (int num) {
        int ret = 0;
        while (num % 2 == 0) {
            num /= 2;
            ret++;
        }
        return ret - 1;
    }

    private static boolean isTwo (int num) {
        while (num % 2 == 0) {
            num /= 2;
        }
        return num == 1 ? true : false;
    }

    private static int distanceTo (int num) {
        int[] arr = new int[18];
        int tmp = 0;
        arr[0] = 2;
        for (int i = 1; i < 18; i++) {
            arr[i] = 2 * arr [i - 1];
        }
        for (int i = 0; i < 18; i++) {
            if (num > arr[i]) {
                tmp = Math.min(num - arr[i], arr[i + 1] - num);
            }
        }
        return tmp;
    }
}
